package com.zxs.domain.service.impl;

import com.zxs.common.enums.IsDeleteCodeEnum;
import com.zxs.domain.convert.SubjectLabelConvert;
import com.zxs.domain.entity.bo.SubjectLabelBO;
import com.zxs.domain.service.SubjectLabelDomainService;
import com.zxs.infra.basic.entity.SubjectLabel;
import com.zxs.infra.basic.entity.SubjectMapping;
import com.zxs.infra.basic.mapper.SubjectMappingMapper;
import com.zxs.infra.basic.service.SubjectLabelService;
import com.zxs.infra.basic.service.SubjectMappingService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 题目标签
 * @author zxs
 * @date 2025/11/4 下午9:15
 */
@Service
public class SubjectLabelDomainServiceImpl implements SubjectLabelDomainService {

    private static final Logger log = LoggerFactory.getLogger(SubjectLabelDomainServiceImpl.class);

    @Autowired
    private SubjectLabelService subjectLabelService;

    @Autowired
    private SubjectMappingService subjectMappingService;

    @Autowired
    private SubjectMappingMapper subjectMappingMapper;

    @Override
    public Boolean addSubjectLabel(SubjectLabelBO subjectLabelBO) {
        SubjectLabel subjectLabel = SubjectLabelConvert.INSTANCE.convertBoToLabel(subjectLabelBO);
        subjectLabel.setCreatedTime(new Date());
        subjectLabel.setIsDelete(IsDeleteCodeEnum.UN_DELETED.getCode());
        SubjectLabel insert = subjectLabelService.insert(subjectLabel);
        if (insert == null) {
            return false;
        }
        return true;
    }

    @Override
    public Boolean updateSubjectLabel(SubjectLabelBO subjectLabelBO) {
        SubjectLabel subjectLabel = SubjectLabelConvert.INSTANCE.convertBoToLabel(subjectLabelBO);
        subjectLabel.setUpdateTime(new Date());
        SubjectLabel update = subjectLabelService.update(subjectLabel);
        if (update == null) {
            return false;
        }
        return true;

    }

    @Override
    public Boolean deleteSubjectLabel(SubjectLabelBO subjectLabelBO) {
        SubjectLabel subjectLabel = SubjectLabelConvert.INSTANCE.convertBoToLabel(subjectLabelBO);
        subjectLabel.setUpdateTime(new Date());
        subjectLabel.setIsDelete(IsDeleteCodeEnum.DELETED.getCode());
        SubjectLabel update = subjectLabelService.update(subjectLabel);
        if (update == null) {
            return false;
        }
        return true;

    }

    /**
     * 根据分类id查询标签
     * @param subjectLabelBO
     * @return
     */
    @Override
    public List<SubjectMapping> queryByCategoryId(SubjectLabelBO subjectLabelBO) {
        //分类ID
        Integer categoryId = subjectLabelBO.getCategoryId();

        SubjectMapping subjectMapping = new SubjectMapping();
        subjectMapping.setCategoryId(categoryId);
        subjectMapping.setIsDelete(IsDeleteCodeEnum.UN_DELETED.getCode());

        List<SubjectMapping> subjectLabels = subjectMappingService.queryLiable(subjectMapping);
        return subjectLabels;
    }
}